package com.beinhospital_sw21_h2_05.beinhospitalsw21h205.controller;

import com.beinhospital_sw21_h2_05.beinhospitalsw21h205.entity.MedicalOrder;
import com.beinhospital_sw21_h2_05.beinhospitalsw21h205.service.MedicalOrderService;
import com.beinhospital_sw21_h2_05.beinhospitalsw21h205.utils.PageBean;
import com.beinhospital_sw21_h2_05.beinhospitalsw21h205.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 控制器类，处理与医嘱（MedicalOrder）相关的HTTP请求
 */
@CrossOrigin
@Slf4j
@RestController
public class MedicalOrderController {

    @Autowired
    private MedicalOrderService medicalOrderService;

    /**
     * 病人分页查询
     * @param page 页码，默认为1
     * @param pageSize 每页大小，默认为10
     * @param bed_number 病床号，可选
     * @return 分页查询结果
     */
    @GetMapping("/medicalOrder")
    public Result page(@RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer pageSize,
                       String bed_number) {
        log.info("病人分页查询：{}，{}, {}", page, pageSize, bed_number);
        PageBean pageBean = medicalOrderService.page(page, pageSize, bed_number);
        return Result.success(pageBean);
    }

    /**
     * 添加医生嘱咐
     * @param medicalOrder 包含医生嘱咐信息的对象
     * @return 操作结果
     */
    @PostMapping("/medicalOrder")
    public Result insert(@RequestBody MedicalOrder medicalOrder) {
        log.info("医生嘱咐：{}", medicalOrder);
        medicalOrderService.add(medicalOrder);
        return Result.success();
    }
}
